From: tsteven4 Date: Thu, 11 Oct 2018 17:28:41 +0000 (-0600) Subject: correct sort filter time option to use msecs. X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~8^2~82^2 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=fe5fac14ca0543b10adff7f198e791069a073f87;p=gpsbabel.git correct sort filter time option to use msecs. --- diff --git a/reference/sortfilter_in.gpx b/reference/sortfilter_in.gpx new file mode 100644 index 000000000..2fb72cad4 --- /dev/null +++ b/reference/sortfilter_in.gpx @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/reference/sortfilter_out.gpx b/reference/sortfilter_out.gpx new file mode 100644 index 000000000..2feb73b02 --- /dev/null +++ b/reference/sortfilter_out.gpx @@ -0,0 +1,29 @@ + + + + + + + WPT004 + WPT004 + WPT004 + + + + WPT002 + WPT002 + WPT002 + + + + WPT001 + WPT001 + WPT001 + + + + WPT003 + WPT003 + WPT003 + + diff --git a/sort.cc b/sort.cc index a50be2c73..8c096d345 100644 --- a/sort.cc +++ b/sort.cc @@ -25,6 +25,12 @@ #if FILTERS_ENABLED +template +inline int sgn(T v) { +// Returns 1 if v > 0, -1 if v < 0, and 0 if v is zero + return (v > T(0)) - (v < T(0)); +} + int SortFilter::sort_comp(const queue* a, const queue* b) { const Waypoint* x1 = reinterpret_cast(a); @@ -38,7 +44,7 @@ int SortFilter::sort_comp(const queue* a, const queue* b) case sm_description: return x1->description.compare(x2->description); case sm_time: - return x1->GetCreationTime().toTime_t() - x2->GetCreationTime().toTime_t(); + return sgn(x2->GetCreationTime().msecsTo(x1->GetCreationTime())); default: abort(); return 0; /* Internal caller error. */ diff --git a/testo.d/sort.test b/testo.d/sort.test new file mode 100644 index 000000000..cc00b34c0 --- /dev/null +++ b/testo.d/sort.test @@ -0,0 +1,9 @@ +# +# sort filter tests +# + +rm -f ${TMPDIR}/sortfilter* + +gpsbabel -i gpx -f ${REFERENCE}/sortfilter_in.gpx -x sort,time -o gpx -F ${TMPDIR}/sortfilter_out.gpx +compare ${REFERENCE}/sortfilter_out.gpx ${TMPDIR}/sortfilter_out.gpx +